---
title: "How to stream Postgres to AWS SQS"
sidebarTitle: "AWS SQS"
description: "Connect Postgres to SQS with Sequin. Stream database changes for reliable message queuing with ordered delivery guarantees."
---

This guide shows you how to set up Postgres change data capture (CDC) and stream changes to SQS using Sequin.

With Postgres data streaming to SQS, you can trigger workflows, keep services in sync, [build audit logs](/how-to/create-audit-logs), [maintain caches](/how-to/maintain-caches), and more.

By the end of this how-to, you'll have database changes flowing to an SQS queue.

<Tip>
  This is the how-to guide for streaming Postgres to SQS. See the [quickstart](/quickstart/sqs) for a step-by-step walkthrough or the [reference](/reference/sinks/sqs) for details on all configuration options.
</Tip>

## Prerequisites

If you're self-hosting Sequin, you'll need:

1. [Sequin installed](/running-sequin)
2. [A database connected](/connect-postgres)



## Basic setup

### Create an SQS queue

If you don't have an SQS queue already, create one in your AWS account.

Most likely, you'll want to create a FIFO queue. This will ensure your system [receives events pertaining to the same row in order](/reference/sinks/sqs#grouping-and-ordering).

### Create an IAM user for Sequin

First, create an IAM user that Sequin will use to send messages to your SQS queue:

1. Navigate to the IAM service in your AWS Console
2. Click "Users" then "Create user"
3. Name the user (e.g., "sequin-sqs-publisher")
4. Select "Access key - Programmatic access"

<Accordion title="Required IAM Policy">
  ```json
  {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Action": [
          "sqs:SendMessage",
          "sqs:SendMessageBatch",
          "sqs:GetQueueAttributes",
          "sqs:GetQueueUrl",
          "sqs:ListQueues",
          "sqs:ListQueueTags",
          "sqs:ChangeMessageVisibility"
        ],
        "Resource": "<your-queue-arn>"
      }
    ]
  }
  ```
</Accordion>

Replace `<your-queue-arn>` with your actual queue ARN (e.g., `arn:aws:sqs:us-east-1:123456789012:my-queue`).

After creating the user, save the Access Key ID and Secret Access Key - you'll need these when configuring the SQS sink in Sequin in a moment.

### (Optional) Enable retention for changes

Sequin stores `insert`, `update`, and `delete` changes in a buffer until they're delivered to SQS.

You can use [change retention](reference/change-retention) to persist changes to a table in your database. Then, you can stream _that_ table to SQS. This gives you the power to [run backfills](/reference/backfills)/replays of recent changes at any times.

## Create SQS sink

Navigate to the "Sinks" tab, click "Create Sink", and select "SQS Sink".

### Configure the source

<Steps>
  <Step title="Select source tables">
    Under "Source", select the schemas and tables you want to stream data from.
  </Step>

  <Step title="Add filters (optional)">
    Add [filters](/reference/filters) to the sink to control which database changes are sent to your SQS queue.
  </Step>

  <Step title="Add transform (optional)">
    Add a [transform](/reference/transforms) to the sink to modify the payload before it's sent to SQS.
  </Step>

  <Step title="Specify backfill">
    You can optionally indicate if you want SQS to receive a [backfill](reference/backfills) of all or a portion of the table's existing data. Backfills are useful if you want to use SQS to process historical data. For example, if you're materializing a cache, you might want to warm it with existing rows.

    You can backfill at any time. If you don't want to backfill, toggle "Backfill" off.
  </Step>

  <Step title="Specify message grouping">
    Under "Message grouping", you'll most likely want to leave the default option selected to ensure events for the same row are sent to SQS in order.

    That way, if you're using an SQS FIFO queue, your system will receive events for a row in the [same order they occurred in](reference/sinks/sqs#grouping-and-ordering).
  </Step>

</Steps>

### Configure SQS

<Steps>
  <Step title="Enter queue details">
    Fill in the queue's URL, as well as the AWS client ID and secret you configured for Sequin.

    <Info>
      If your queue is a FIFO queue, be sure to include the `.fifo` extension in the queue's URL.
    </Info>
  </Step>

  <Step title="Create the sink">
    Give your sink a name, then click "Create SQS Sink".
  </Step>
</Steps>

<Note>
  Need to send messages to multiple queues? Use Sequin's [SNS sink](/how-to/stream-postgres-to-sns) with SQS subscriptions.
</Note>

## Verify & debug

To verify that your SQS sink is working:

1. Make some changes in your source table.
2. Verify that the count of messages for your sink increases in the Sequin web console.
3. In the AWS Console, navigate to your queue. Click "Send and receive messages" then "Poll for messages". You should see the messages from Sequin appear in the table below.

If messages don't seem to be flowing:

1. Click the "Messages" tab to view the state of messages for your sink
2. Click any failed message
3. Check the delivery logs for error details, including any AWS API errors

## Next steps

- **Setup a processor**

   Now that your Postgres data is flowing into SQS, you can setup a processor to read from the queue and process the data. See the AWS docs on [receiving and processing messages](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-getting-started.html#step-receive-delete-message).

   Refer to the [SQS sink reference](/reference/sinks/sqs) for the shape of messages that Sequin will publish to SQS.

- **Deploy your implementation**

   When you're ready to deploy your implementation, see "[How to deploy to production](/how-to/deploy-to-production)".

- **Advanced configuration**

   For more about how SQS sinks work, see the [SQS sink reference](/reference/sinks/sqs).
